package com.china.school;

import com.china.school.pojo.User;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterAdvice;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Method;

public class MethodBeforeAdviceTest implements MethodBeforeAdvice, AfterAdvice, AfterReturningAdvice,
        MethodInterceptor, ThrowsAdvice
{
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("MethodBeforeAdviceTest.xml");
        User user = ctx.getBean(User.class);

        user.eat();

//TransactionInterceptor

    }
    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("before。。");
//        method.invoke(target, args);

    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("around-----前");
        Object res = invocation.proceed();
        System.out.println("around-----后");
        return res;
    }



    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("afterReturning----------");
    }


}
